package com.aspose.cells;

class zajx {
   private zoz a = null;

   zajx(zoz var1) {
      this.a = var1;
   }

   void a(zcfw var1) throws Exception {
      this.d(var1);
      if (!var1.n()) {
         var1.d();

         while(zass.a(var1)) {
            if ("sheets".equals(var1.p())) {
               this.b(var1);
            } else if ("definedNames".equals(var1.p())) {
               this.c(var1);
            } else {
               var1.a();
            }
         }

      }
   }

   private void b(zcfw var1) throws Exception {
      this.a.a.getWorksheets().clear();
      if (var1.n()) {
         var1.a();
      } else {
         zhu.c();
         int var2 = 0;
         var1.d();

         while(true) {
            do {
               label60:
               do {
                  while(var1.r() != 4) {
                     var1.j();
                     if (var1.r() == 1) {
                        continue label60;
                     }

                     var1.a();
                  }

                  var1.h();
                  return;
               } while(!"sheet".equals(var1.p()));
            } while(!var1.m());

            String var3 = null;
            String var4 = null;
            String var5 = null;
            String var6 = null;
            String var7 = null;

            while(var1.l()) {
               if ("name".equals(var1.p())) {
                  var3 = var1.s();
               } else if ("sheetId".equals(var1.p())) {
                  zase.C(var1.s());
                  var4 = var1.s();
               } else if ("id".equals(var1.p())) {
                  var5 = var1.s();
               } else if ("type".equals(var1.p())) {
                  var6 = var1.s();
               } else if ("state".equals(var1.p())) {
                  var7 = var1.s();
               }
            }

            if (var6 == null || "chartsheet".equals(var6)) {
               if (var3 == null || var3.length() == 0 || var5 == null || var5.length() == 0 || var4 == null) {
                  throw new CellsException(6, "invalid sheet attributes data");
               }

               Worksheet var8 = this.a.a.getWorksheets().get(this.a.a.getWorksheets().add());
               var8.b(var3);
               if (var7 != null) {
                  if ("hidden".equals(var7)) {
                     var8.a(false, false);
                  } else if ("veryHidden".equals(var7)) {
                     var8.a(false, true);
                  }
               }

               this.a.a(var8, var2, var4, var5);
            }

            var1.k();
            var1.a();
            ++var2;
         }
      }
   }

   private void c(zcfw var1) throws Exception {
      if (var1.n()) {
         var1.a();
      } else {
         var1.d();
         WorksheetCollection var2 = this.a.a.getWorksheets();

         while(true) {
            label62:
            do {
               while(var1.r() != 4) {
                  var1.j();
                  if (var1.r() == 1) {
                     continue label62;
                  }

                  var1.a();
               }

               var1.h();
               return;
            } while(!"definedName".equals(var1.p()));

            int var3 = -1;
            boolean var4 = false;
            String var5 = null;
            String var6 = null;
            if (var1.m()) {
               while(var1.l()) {
                  if ("name".equals(var1.p())) {
                     var5 = var1.s();
                  } else if ("localSheetId".equals(var1.p())) {
                     var3 = zase.C(var1.s());
                  } else if ("hidden".equals(var1.p())) {
                     var4 = "1".equals(var1.s());
                  }
               }

               var1.k();
            }

            var6 = var1.i();
            if (var5 == null || var6 == null) {
               throw new CellsException(6, "Invalid name data");
            }

            if (var6.toUpperCase().indexOf("#REF") == -1 && var6.indexOf(91) == -1) {
               String var7 = var5.toUpperCase();
               boolean var8 = var7.startsWith("_XLNM.");
               if (var8) {
                  var5 = var5.substring(6);
                  var7 = var5.toUpperCase();
               }

               if (var3 != -1) {
                  var3 = this.a.a(var3).getIndex();
               }

               int var9 = var2.getNames().a(var3, var5);
               Name var10 = var2.getNames().get(var9);
               if (var8) {
                  var10.f(var7);
               }

               var10.setRefersTo("=" + var6);
               var10.a(var4);
            }
         }
      }
   }

   private void d(zcfw var1) throws Exception {
      var1.j();
      if (var1.r() != 1 || !"workbook".equals(var1.p())) {
         throw new CellsException(6, "workbook root element eror");
      }
   }
}
